package com.example.sayhello.controllers;

import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by Administrator on 2016/10/11.
 */
@RestController
public class HelloController  {
    private final Logger logger = LoggerFactory.getLogger(HelloController.class);
    @Autowired
    private DiscoveryClient client;

    @RequestMapping(value = "/say/{text}" ,method = RequestMethod.GET)
    public Map say(@PathVariable("text") String text) {
        ServiceInstance instance = client.getLocalServiceInstance();
        Map<String,String> result = Maps.newHashMap();
        result.put("say","hi,"+text);
        logger.info("/say, host:{},service_id:{},result:{}" ,instance.getHost(),instance.getServiceId(),result);
        return result;
    }
}
